const express = require('express')
const path = require('path')
const app = express()

app.set('secret', 'qwertyuiop')

app.use(require('cors')()) // 跨域
app.use(express.json())

app.use('/', express.static(path.join(__dirname, 'web')))
app.use('/admin', express.static(path.join(__dirname, 'admin')))
app.use('/uploads', express.static(path.join(__dirname, 'uploads')))

require('./plugins/db')(app)
require('./routes/admin')(app)
require('./routes/web')(app)

// 错误拦截
app.use(require('./middleware/error'))

// 启动监听
app.listen(3000, () => {
console.log('http://localhost:3000')
})